<?php

//创建
if(isset($_POST['database1'])){
	$database1 = trim($_POST['database1']);

$con = mysql_connect("localhost","root","flower");
if(!$con){
	echo "连接数据库失败";
}
$sql = "create database if not exists {$database1}";
$bool = mysql_query($sql);
if(!$bool){
	echo "创建数据库失败",mysql_error($con),"<br>";
}
mysql_close($con);
echo "<script>window.parent.location='index.php'</script>";
}
//删除
if(isset($_POST['database2'])){
	$database2 = $_POST['database2'];
	$con = mysql_connect("localhost","root","flower");
	if(!$con){
		echo "连接数据库失败";
	}
	if($database2!='information_schema'and $database2!='mysql'){
		$sql = "drop database {$database2}";
	}
	$bool1 = mysql_query($sql);
	if(!$bool1){
		echo "删除数据库失败";
	}
	mysql_close($con);
	
}
//数据库数组
$con = mysql_connect("localhost","root","flower");
if($con){
	//echo "数据库连接成功";
}else {
	echo "数据库连接不成功";
}
mysql_query("set names utf8");
$sql = "show databases";
$res = mysql_query($sql);
if($res){
	while($one_arr[] = mysql_fetch_array($res)){
		$one_arr[] = mysql_fetch_array($res);
	}
}
mysql_close($con);


?>


<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>无标题文档</title>
<style>
	#a1{
		color:white;
		font-size:20px;
	}
	.a11{
		background-color:#E8728A;
		color:white;
	}
	.a21{
		color:white;
		background-color:#E8728A;
	}
	#a2{
		color:white;
		margin-top:50px;
		font-size:20px;
	}
</style>
</head>

<body bgcolor="#FCB6B8">
<form action="" method="post">
	<div id=a1>
	数据库名：<input type="text" name="database1"/>
	<input type="submit" value="创建" class="a11"/>
	
	</div>
	<div id=a2>
	数据库名：<select name="database2">
		<option selected="selected">请选择要删除的数据库</option>
		<?php foreach($one_arr as $v){?>
		<option><?php echo $v[0]?></option>
		<?php }?>
	</select>
	<input type="submit" value="删除" class="a21"/>
	</div>
</form>
</body>
</html>
